package com.senmiao.ssm.controller;

import com.senmiao.ssm.aspect.annotation.DoDeleteLog;
import com.senmiao.ssm.aspect.annotation.DoInsertLog;
import com.senmiao.ssm.aspect.annotation.DoUpdateEmployeeLog;
import com.senmiao.ssm.service.BusinessService;
import com.senmiao.ssm.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 业务管理员controller
 */
@RestController
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    /**
     * 通过id获取员工信息
     * @param employeeId
     * @return
     */
    @RequiresPermissions("/emp/getById:get")
    @RequestMapping("/emp/getById")
    public Result getEmployeeById(Integer employeeId){
        return businessService.getEmployeeById(employeeId);
    }

    /**
     * 新增员工
     * @param name
     * @param age
     * @param sex
     * @return
     */
    @RequiresPermissions("/emp/create:post")
    @DoInsertLog(tableName = "tb_employee")
    @RequestMapping("/emp/create")
    public Result createEmployee(String name,Integer age,Integer sex){
        return businessService.createEmployee(name,age,sex);
    }

    /**
     * 修改员工信息
     * @param employeeId
     * @param name
     * @param age
     * @param sex
     * @return
     */
    @RequiresPermissions("/emp/update:post")
    @DoUpdateEmployeeLog(tableName = "tb_employee")
    @RequestMapping("/emp/update")
    public Result updateEmployee(Integer employeeId,String name,Integer age,Integer sex){
        return businessService.updateEmployee(employeeId,name,age,sex);
    }

    /**
     * 删除员工
     * @param employeeIds
     * @return
     */
    @RequiresPermissions("/emp/delete:post")
    @DoDeleteLog(tableName = "tb_employee")
    @RequestMapping("/emp/delete")
    public Result deleteEmployees(@RequestParam("employeeId") List<Integer> employeeIds){
        return businessService.deleteEmployeeByIds(employeeIds);
    }

    /**
     * 查询员工列表
     * @param pageNum
     * @param limit
     * @return
     */
    @RequiresPermissions("/emp/getList:get")
    @RequestMapping("/emp/getList")
    public Result listEmployee(Integer pageNum,Integer limit){
        return businessService.listEmployee(pageNum,limit);
    }
}